/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package popups;

/**
 *
 * @author icdev
 */
import java.io.File;
import javax.swing.table.DefaultTableModel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class PopupFormManager {

        public static DefaultTableModel getComponents(String elementName) {
        DefaultTableModel dtm = new DefaultTableModel();
        try {

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(false);
            DocumentBuilder docbuilder = factory.newDocumentBuilder();
            Document doc = docbuilder.parse(new File("resources/Resources.xml"));
            NodeList nodlst = doc.getElementsByTagName(elementName);
            dtm.setColumnCount(0);
            dtm.setRowCount(0);
            dtm.addColumn("type");
            dtm.addColumn("image_url");
            for (int i = 0; i < nodlst.getLength(); i++) {
                Element element = (Element) nodlst.item(i);
                String elemImage = element.getAttribute("image_url");
                String elemType = element.getAttribute("type");
                dtm.addRow(new Object[]{elemType, elemImage});
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return dtm;
    }
}
